package com.example.administrator.u17.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.u17.R;
import com.example.administrator.u17.modle.DingYueBean;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

/**
 * Created by Smile on 2016/11/14.
 */

public class DingYueAdapter extends BaseAdapter {

    private ArrayList<DingYueBean.Comics> mData;
    private Context mContext;

    public DingYueAdapter(Context mContext, ArrayList<DingYueBean.Comics> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData==null?0:mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView=View.inflate(mContext,R.layout.dingyue_item,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        Picasso.with(mContext).load(mData.get(position).cover).into(holder.imageView);;
//        holder.tvTime.setText(mData.get(position).);
        holder.tvName.setText(mData.get(position).name);
        holder.tvInfo.setText(mData.get(position).description);
        StringBuilder builder=new StringBuilder();
        for (int i = 0; i < mData.get(position).tags.size(); i++) {
            builder.append(mData.get(position).tags.get(i)+" ");
        }
        holder.tvFlag.setText(builder.toString());

        return convertView;
    }
class ViewHolder{
    ImageView imageView;
    TextView tvName,tvFlag,tvInfo,tvTime;
    public ViewHolder(View view){
        imageView= (ImageView) view.findViewById(R.id.iv_dingyue_item);
        tvFlag= (TextView) view.findViewById(R.id.tv_flag_dingyue_item);
        tvInfo= (TextView) view.findViewById(R.id.tv_info_dingyue_item);
        tvName= (TextView) view.findViewById(R.id.tv_name_dingyue_item);
        tvTime= (TextView) view.findViewById(R.id.tv_time_dingyue_item);
    }
}
}
